CREATE OR REPLACE VIEW VAC_APP_PAGE_IR AS
with ir as
(
select
 workspace,
 application_id,
 application_name,
 page_id,
 interactive_report_id,
 region_id,
 region_name,
 TO_CHAR(number_of_columns)             number_of_columns,
 TO_CHAR(number_of_column_groups)       number_of_column_groups,
 TO_CHAR(number_of_alt_default_reports) number_of_alt_default_reports,
 TO_CHAR(number_of_public_reports)      number_of_public_reports,
 TO_CHAR(number_of_private_reports)     number_of_private_reports,
 TO_CHAR(max_row_count)                 max_row_count,
 max_row_count_message,
 no_data_found_message,
 max_rows_per_page,
 search_button_label,
 page_items_to_submit,
 sort_asc_image,
 sort_asc_image_attr,
 sort_desc_image,
 sort_desc_image_attr,
 base_table_or_view,
-- sql_query,
 ac_utils.hs(sql_query) sql_query_hs,
 dbms_lob.substr(sql_query,4000, 1)        sql_query_sr1,
 dbms_lob.substr(sql_query,4000, 4000+1 )  sql_query_sr2,
 dbms_lob.substr(sql_query,4000, 8000+1 )  sql_query_sr3,
 dbms_lob.substr(sql_query,4000, 12000+1)  sql_query_sr4,
 show_nulls_as,
 pagination_scheme,
 pagination_display_position,
 button_template,
 show_finder_drop_down,
 show_reports_select_list,
 show_display_row_count,
 show_search_bar,
 show_search_textbox,
 show_actions_menu,
 actions_menu_icon,
 finder_icon,
 show_select_columns,
 show_rows_per_page,
 show_filter,
 show_sort,
 show_control_break,
 show_highlight,
 show_compute,
 show_aggregate,
 show_chart,
 show_group_by,
 show_notify,
 show_flashback,
 show_save,
 show_save_public,
 save_public_auth_scheme,
 save_public_auth_scheme_id, --
 show_reset,
 show_download,
 show_help,
 download_formats,
 filename,
 separator,
 enclosed_by,
 detail_link_type,
 detail_link_target,
 detail_link_text,
 detail_link_attributes,
 detail_link_checksum_type,
 detail_link_condition_type,
 detail_link_cond_expression,
 detail_link_cond_expression2,
 detail_link_auth_scheme,
 detail_link_auth_scheme_id, --
 alias,
 report_id_item,
 max_query_cost,
 icon_view_enabled_yn,
 icon_view_link_column,
 icon_view_img_src_column,
 icon_view_label_column,
 icon_view_img_attr_text,
 icon_view_alt_text,
 icon_view_title_text,
 TO_CHAR(icon_view_columns_per_row) icon_view_columns_per_row,
 detail_view_enabled_yn,
 detail_view_before_rows,
 detail_view_for_each_row,
 detail_view_after_rows,
 created_on,
 created_by,
 updated_on,
 updated_by,
 component_signature
from APEX_APPLICATION_PAGE_IR
)
SELECT
 workspace,
 application_id,
 application_name,
 page_id,
 interactive_report_id,
 region_id,
 region_name,
 to_clob(sql_query_sr1)    || to_clob(sql_query_sr2)
 || to_clob(sql_query_sr3) || to_clob(sql_query_sr4)  sql_query,
 save_public_auth_scheme_id, --
 detail_link_auth_scheme_id, --
 created_on,
 created_by,
 updated_on,
 updated_by,
 component_signature,
 'APEX_APPLICATION_PAGE_IR' src_view_name,
 u_name,
 u_value
FROM
(
select
 workspace,
 application_id,
 application_name,
 page_id,
 interactive_report_id,
 region_id,
 region_name,
 sql_query_sr1,
 sql_query_sr2,
 sql_query_sr3,
 sql_query_sr4,
 save_public_auth_scheme_id, --
 detail_link_auth_scheme_id, --
 created_on,
 created_by,
 updated_on,
 updated_by,
 component_signature,
 u_name,
 u_value
from ir
UNPIVOT INCLUDE NULLS
 ( u_value
   FOR    u_name
   IN
   ( number_of_columns,
     number_of_column_groups,
     number_of_alt_default_reports,
     number_of_public_reports,
     number_of_private_reports,
     max_row_count,
     max_row_count_message,
     no_data_found_message,
     max_rows_per_page,
     search_button_label,
     page_items_to_submit,
     sort_asc_image,
     sort_asc_image_attr,
     sort_desc_image,
     sort_desc_image_attr,
     base_table_or_view,
     sql_query_hs,
     show_nulls_as,
     pagination_scheme,
     pagination_display_position,
     button_template,
     show_finder_drop_down,
     show_reports_select_list,
     show_display_row_count,
     show_search_bar,
     show_search_textbox,
     show_actions_menu,
     actions_menu_icon,
     finder_icon,
     show_select_columns,
     show_rows_per_page,
     show_filter,
     show_sort,
     show_control_break,
     show_highlight,
     show_compute,
     show_aggregate,
     show_chart,
     show_group_by,
     show_notify,
     show_flashback,
     show_save,
     show_save_public,
     save_public_auth_scheme,
     show_nulls_as,
     pagination_scheme,
     pagination_display_position,
     button_template,
     show_finder_drop_down,
     show_reports_select_list,
     show_display_row_count,
     show_search_bar,
     show_search_textbox,
     show_actions_menu,
     actions_menu_icon,
     finder_icon,
     show_select_columns,
     show_rows_per_page,
     show_filter,
     show_sort,
     show_control_break,
     show_highlight,
     show_compute,
     show_aggregate,
     show_chart,
     show_group_by,
     show_notify,
     show_flashback,
     show_save,
     show_save_public,
     save_public_auth_scheme,
     show_reset,
     show_download,
     show_help,
     download_formats,
     filename,
     separator,
     enclosed_by,
     detail_link_type,
     detail_link_target,
     detail_link_text,
     detail_link_attributes,
     detail_link_checksum_type,
     detail_link_condition_type,
     detail_link_cond_expression,
     detail_link_cond_expression2,
     detail_link_auth_scheme,
     alias,
     report_id_item,
     max_query_cost,
     icon_view_enabled_yn,
     icon_view_link_column,
     icon_view_img_src_column,
     icon_view_label_column,
     icon_view_img_attr_text,
     icon_view_alt_text,
     icon_view_title_text,
     icon_view_columns_per_row,
     detail_view_enabled_yn,
     detail_view_before_rows,
     detail_view_for_each_row,
     detail_view_after_rows
   )
 )
) t;

